﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace GeometryViz3D.Views
{
    /// <summary>
    /// Interaction logic for ControlPanel.xaml
    /// </summary>
    public partial class ControlPanel : Window
    {
        public enum SliderId
        {
            AxisX,
            AxisY,
            AxisZ,
            Distance
        }

        public ControlPanel()
        {
            InitializeComponent();
        }

        public int AxisX
        {
            get;
            set;
        }

        public int AxisY
        {
            get;
            set;
        }

        public int AxisZ
        {
            get;
            set;
        }

        public double Distance
        {
            get { return sliderDistance.Value; }
            set { sliderDistance.Value = value; }
        }

        public double MinDistance
        {
            get { return sliderDistance.Minimum; }
            set { sliderDistance.Minimum = value; }
        }

        public double MaxDistance
        {
            get { return sliderDistance.Maximum; }
            set { sliderDistance.Maximum = value; }
        }

        public void Bind(DependencyObject target, DependencyProperty property, SliderId id)
        {
            if (target == null || property == null)
            {
                throw new ArgumentNullException("The target and property parameters should not be null");
            }

            switch (id)
            {
                case SliderId.AxisX:
                    Bind(target, property, sliderX);
                    break;

                case SliderId.AxisY:
                    Bind(target, property, sliderY);
                    break;

                case SliderId.AxisZ:
                    Bind(target, property, sliderZ);
                    break;

                case SliderId.Distance:
                    Bind(target, property, sliderDistance);
                    break;

                default:
                    throw new ArgumentException("Invalid SliderId");
            }
        }

        private void Bind(DependencyObject target, DependencyProperty property, Slider slider)
        {
            Binding binding = new Binding();
            binding.Source = slider; ;
            binding.Path = new PropertyPath("Value");
            binding.Mode = BindingMode.TwoWay;
            BindingOperations.SetBinding(target, property, binding);
        }
    }
}
